// pages/retail/order/index.js
import api from '../../../utils/api'
import message from '../../../utils/message'
Page({

    /**
     * 页面的初始数据
     */
    data: {

        retail_id:null,
        no_data:false,
        has_load:false,
        retail_order_list:[],
        page_index:1,
        status:0

    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        if(options.id){
            this.setData({
                retail_id: options.id
            })

            this.getRetailUserOrderList();
        }

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    },
    getRetailUserOrderList:function (params) {
        var me = this;

        var params = {}

        var page_index = this.data.page_index;


        if(this.data.has_load){
            page_index++;
        }
        params.page_index =  page_index;
        params.retail_id = this.data.retail_id;
        params.status = this.data.status;

        message.show_loading();

        api.retail.getRetailUserOrderList( params ,function (response) {
            message.hide_loading();

            if(response.status==1) {

                var no_data = false;
                if(response.data.length<10){
                    no_data = true
                }

                var order_list = me.data.retail_order_list;

                order_list = order_list.concat( response.data );
                me.setData({
                    page_index:page_index,
                    has_load:true,
                    retail_order_list:order_list,
                    no_data:no_data
                })

            }  
        })
        
    },
    selectTab:function (e) {
        var status = e.currentTarget.dataset.status;

        //if(status){
            this.setData({
                has_load: false,
                status: status,
                retail_order_list: [],
                no_data: false,
                page_index:1
            })

            this.getRetailUserOrderList();
        //}
    }
})